package com.jt.demos;

import redis.clients.jedis.Jedis;

import java.util.Set;

public class VoteDemo01{
 private static Jedis jedis=new Jedis("192.168.126.129",6379);

 static void vote(String activityId,String userId){
  jedis.sadd(activityId,userId);
 }

 static Long getVoteCount(String activityId){
  Long count=jedis.scard(activityId);
  return count;
 }


  static Set<String> getVoteUsers(String activityId){
  Set<String> smembers=jedis.smembers(activityId);
  return smembers;
  }


  static boolean checkVote(String activityId,String userId){
   Boolean flag=jedis.sismember(activityId,userId);
   return flag;
  }


 public static void main(String[] args){
  String activityId="10001";
  String user1="201";
  String user2="202";
  String user3="203";
  vote(activityId,user1);
  vote(activityId,user2);
  vote(activityId,user3);
   Long voteCount=getVoteCount(activityId);
  System.out.println("投票次数："+voteCount);
  Set<String> users=getVoteUsers(activityId);
  System.out.println(users);
  boolean flag=checkVote(activityId,user1);
  System.out.println(flag?"已投过票":"还没投票");
 }
}










